﻿using FS.Common.DotNetBean;
using FS.Common.DotNetCode;
using FS.Common.DotNetUI;
using FS.Web;
using FS.Business;
using System;
using System.Collections;
using System.Data;
using System.Web.UI.WebControls;

namespace FS.Web.BLL.Visa_info
{
    public partial class Visa_InfoAddForm : PageBase
    {
        private string _key;
        visa_dao _visa = new visa_dao();
        protected void Page_Load(object sender, EventArgs e)
        {
            this._key = base.Request["key"];            
            string ls_viewSupply = RequestSession.GetSessionUser().isViewSupply;
            string ls_viewPrice = RequestSession.GetSessionUser().isViewPrice;
            
            this.HD_viewSupply.Value = ls_viewSupply;
            this.HD_viewPrice.Value = ls_viewPrice;

            if (!base.IsPostBack)
            {
                            
                #region 权限控制
                if (ls_viewPrice == "0")
                {
                    this.div_price1.Visible = false;
                    this.div_price2.Visible = false;
                }
               
                #endregion
                
                if (string.IsNullOrEmpty(this._key))
                {
                    newInfoid();
                }
                else
                {
                    this.Hinfo.Value = this._key;
                    this.InitData();
                    //DataBindGrid();

                    //编辑权限
                    this.img_trust.Visible = false;
                }
            }
        }

        private void newInfoid()
        {
            this.HD_AddNo.Value = "0";
            this.Hinfo.Value = CommonHelper.GetGuid;
            //设置签证时间
            this.info_getdate.Value = DateTime.Now.ToString("yyyy-MM-dd");                        
        }

        private void InitData()
        {
            Hashtable ht = DataFactory.Run().GetHashtableById("Visa_Info", "Info_ID", this._key);
            if (ht.Count > 0 && ht != null)
            {
                ht["INFO_GETDATE"] = (Convert.ToDateTime(ht["INFO_GETDATE"])).ToString("yyyy-MM-dd");

                string ls_trust = ht["TRUST_ID"].ToString();
                DataTable dt = _visa.GetSelect_trustInfoBytrustid(ls_trust);
                if (dt.Rows.Count > 0)
                {
                    ht["Ref_pricetype"] = dt.Rows[0]["type_price"].ToString();
                    ht["Ref_trusttype"] = dt.Rows[0]["type_trust"].ToString();                   
                }
                ControlBindHelper.SetWebControls(this.Page, ht);
            }
        }       
       
        private void DataBindGrid()
        {
            string ls_infotid = this.Hinfo.Value.Trim();
            DataTable dt = _visa.GetInfoDetail(ls_infotid);
            //ControlBindHelper.BindRepeaterList(dt, this.rp_Item);
        }

        protected void SaveAdd_Click(object sender, EventArgs e)
        {
            newInfoid();
        }       
    }
}